<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>
        <ui:composition template="../templates/default3.xhtml">
            <ui:define name="content">
                <h:form id="updateSupplier" binding="#{supplierManagerBean.loadUpdateSupplier}">
                    <p:panel id="updateSupplierPanel" header="Update Supplier Information">
                        <p:messages />

                        <table border="0" width="100%">
                            <tr>
                                <td>Supplier Id:</td>
                                <td> 
                                    <h:outputText id="supplierId" title="Supplier Id"
                                                  value="#{supplierManagerBean.supplierId}">
                                    </h:outputText>                              
                                </td>

                                <td>Company:</td>
                                <td> 
                                    <h:outputText id="company" title="Company"
                                                  value="#{supplierManagerBean.company}">
                                    </h:outputText>
                                </td>
                            </tr>      
                            <tr>
                                <td>Name:</td>
                                <td> 
                                    <p:inputText required="true" id="name" requiredMessage="Name Required" value="#{supplierManagerBean.name}" >
                                    </p:inputText> 
                                    <font class="fieldNote">*</font>
                                </td>
                                <td>Ranking:</td>
                                <td>                                                                                
                                    <h:selectOneMenu id="ranking" value="#{supplierManagerBean.ranking}">
                                        <f:selectItem id="Poor" itemLabel="Poor" itemValue="Poor" />
                                        <f:selectItem id="Moderate" itemLabel="Moderate" itemValue="Moderate" />
                                        <f:selectItem id="Reliable" itemLabel="Reliable" itemValue="Reliable" />         
                                    </h:selectOneMenu>
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td>Contact:</td>
                                <td>                                                                                
                                    <p:inputText label="contact" required="true" id="contact" requiredMessage="Contact Required" value="#{supplierManagerBean.contact}" validatorMessage="Contact Must Have a Minimum of 8 Digits">
                                        <f:validateLength minimum="8"/>
                                    </p:inputText>
                                    <font class="fieldNote">* Min. 8</font>
                                </td>
                                <td>Email:</td>
                                <td>
                                    <p:inputText required="true" id="email" requiredMessage="Email Required" value="#{supplierManagerBean.email}" validatorMessage="Invalid Email Address Format">
                                        <f:validateRegex pattern="^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$" />
                                    </p:inputText>
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>     
                            <tr>
                                <td valign="top"> Comment:</td>
                                <td valign="top"> 
                                    <p:inputTextarea id="comment" style="width:160px;height:80px;" maxHeight="80" effectDuration="400" value="#{supplierManagerBean.comment}">

                                    </p:inputTextarea>   
                                </td>
                            </tr>        
                        </table>
                    </p:panel>
                    <p:panel header="Update Supplier's Company Address" id="updateSupplier2">
                        <table width="100%" border="0">
                            <tr>
                                <td width="130px" valign="top" > Street:</td>
                                <td valign="top" width="300px"> 
                                    <table border="0">
                                        <tr>
                                            <td>
                                                <p:inputTextarea id="street" required="true" requiredMessage="Street Required" style="width:160px;height:60px;" maxHeight="60" effectDuration="400" value="#{supplierManagerBean.street}">
                                                </p:inputTextarea></td><td> <font class="fieldNote">*</font></td></tr></table>

                                </td>
                                <td valign="top">City:</td>
                                <td valign="top">
                                    <p:inputText  required="true" requiredMessage="City Required" id="city" value="#{supplierManagerBean.city}">
                                    </p:inputText>
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td valign ="top" >Postal: </td>
                                <td valign ="top"> 
                                    <p:inputText label="Postal" required="true" requiredMessage="Postal Required" id="postal" value="#{supplierManagerBean.postal}" validatorMessage="Postal Code Must Have a Minimum of 4 Digits and Maximum of 8 Digits">
                                        <f:validateLength minimum="4" maximum="11"/>
                                    </p:inputText>
                                    <font class="fieldNote">* Min. 4 , Max. 11</font> 
                                </td>
                                <td>
                                     Country: 
                                </td>
                                <td>
                                    <p:inputText required="true" requiredMessage="Country Required" id="country" value="#{supplierManagerBean.country}">
                                    </p:inputText>
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4" align="center"><hr/>
                                    <p:commandButton id="btnUpdateSupplier" value="Update Supplier"
                                                     ajax="true" title="Update the supplier."
                                                     update="updateSupplierPanel"
                                                     actionListener="#{supplierManagerBean.updateASupplier}"/>
                                    &nbsp;&nbsp;&nbsp;
                                    <p:commandButton id="btnBackFromUpdateSupplier" value="Back"
                                                     immediate="true" ajax="true"
                                                     title="Go back to the previous page."
                                                     actionListener="#{supplierManagerBean.back}"/>
                                </td>
                            </tr>
                        </table>
                    </p:panel>

                    <p:panel id="rawMaterialsPanel" header="Selling Types of Raw Material ">
                        <p:messages />
                        <table width="100%" border="0">
                            <tr>
                                <td>Raw Material:</td>
                                <td>
                                    <h:selectOneMenu id="selectOneRawMaterial" value="#{supplierManagerBean.rawMaterial.id}"
                                                     title="Status of the product.">
                                        <f:selectItem itemLabel="Select Raw Material" itemValue="" />
                                        <f:selectItems value="#{supplierManagerBean.rawMaterialsList}" var="rawMaterial" 
                                                       itemLabel="#{rawMaterial.name}" itemValue="#{rawMaterial.id}" />
                                    </h:selectOneMenu>
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" align="center"><hr/>
                                    <p:commandButton id="btnAddSellingRawMaterial" value="Add Raw Material"
                                                     ajax="true" title="Add materials required for this supplier."
                                                     update="rawMaterialsPanel"
                                                     actionListener="#{supplierManagerBean.addSupplierRawMaterial}"/>
                                <br/><br/>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <p:dataTable id="materials" var="material" value="#{supplierManagerBean.rawMaterialsSelling}" selectionMode="single" 
                                                 selection="#{supplierManagerBean.selectedSellingRawMaterial}" update="updateSupplier">
                                        <p:column filterBy="#{material.name}" headerText="Raw Material Name" filterMatchMode="contains">  
                                            <h:outputText value="#{material.name}" />  
                                        </p:column>                                        
                                    </p:dataTable>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" align="center"><hr/>
                                    <p:commandButton id="btnDeleteMaterialRequired" value="Delete Raw Material Supplier is Selling"
                                                     ajax="true" title="Delete Raw Material for this Supplier."
                                                     update="materialsPanel"
                                                     actionListener="#{supplierManagerBean.deleteSupplierRawMaterial}"/>
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
